package com.qf.springmvc.controller;

import com.qf.springmvc.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("api2")
public class DataController {

    @RequestMapping("data1")
    public String data(HttpServletRequest req, HttpSession sess){
        req.setAttribute("name","小天");
        req.setAttribute("age","18");
        sess.setAttribute("date","2022");
        return "welcome";
    }

    @RequestMapping("data2")
    public String data2(Model model){
        model.addAttribute("name","白云");
        model.addAttribute("age","18");
        model.addAttribute("黑土");

        User user = new User();
        user.setName("一号");
        user.setId(11);
        model.addAttribute(user);

        return "welcome";
    }

    @RequestMapping("data3")
    public ModelAndView data3(){
        ModelAndView modelAndView = new ModelAndView("welcome");
        modelAndView.addObject("name","阿天");
        modelAndView.addObject("age","20");
        return modelAndView;
    }
}
